<template>
	<view class="black">
		<!-- 仅在H5跟支付宝小程序上编译 -->
		<!-- #ifdef H5 || MP-ALIPAY -->
		<image class="cover" :src="cover" mode="widthFix"></image>
		<!-- #endif -->
		
		<!-- 仅在微信小程序，app,百度小程序上编译 -->
		<!-- #ifdef MP-WEIXIN || APP-PLUS || MP-BAIDU  -->
		<image @longpress="operator" class="cover" :src="cover" mode="widthFix"></image>
		<!-- #endif -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cover:'',//图片地址
			}
		},
		onLoad(e) {
			//通过api修改导航栏的属性
			uni.setNavigationBarColor({
			    frontColor: '#ffffff',
			    backgroundColor: '#ff0000'
			})
			
			let str = e.cover;//接收传过来的地址
			//字符串替换为https
			this.cover = str.replace(new RegExp('http://122.152.205.72:88','g'),'https://www.itzixi.com:99');
		},
		methods: {
			//手指长按
			operator(){
				//复杂的底部图文菜单
				uni.showActionSheet({
					itemList:['下载图片'],
					success: (res) => {
						if(res.tapIndex == 0){
							uni.showLoading({title:"图片保存中..."});
							uni.downloadFile({
								url:this.cover,
								success:(dowres)=>{
									let temFilePath = dowres.tempFilePath;
									
									//保存图片到系统相册。在微信小程序里需要配置白名单
									//平台差异在 H5跟支付宝小程序里不支持
									uni.saveImageToPhotosAlbum({
										filePath:temFilePath,
										success: () => {
											uni.showToast({
												title:"保存成功",
												duration:2000
											})
										},
										complete: () => {
											uni.hideLoading();
										}
									})
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	@import url("cover.css");
</style>
